﻿using System;
using System.IO;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YArchitech.MEP.Electric.Common;
using HYElectricSetting;
using HYRElectric.WirePlace;

namespace HYRElectric.Equipment
{
	public class WireParameterInfo
	{
		public bool Init(Document doc)
		{
			YArchitech.MEP.Electric.Common.XmlHelper xmlHelper = new YArchitech.MEP.Electric.Common.XmlHelper();
			string text = Path.Combine(Product.WorkingLocation, "WireParam.xml");
			try
			{
				xmlHelper.LoadXml(text, "Root");
			}
			catch (Exception)
			{
				File.Delete(text);
				return false;
			}
			if (!xmlHelper.SelectNode(Path.Combine("Root", "HYConnectWire", "Params")))
			{
				return false;
			}
			string attribute = xmlHelper.GetAttribute("WireType");
			if (!string.IsNullOrEmpty(attribute))
			{
				this.strWireType = attribute;
			}
			WireConnectForm.wireParams.WireType = this.strWireType;
			string attribute2 = xmlHelper.GetAttribute("WireNum");
			if (!string.IsNullOrEmpty(attribute2))
			{
				this.nWireNum = Convert.ToInt32(attribute2);
			}
			WireConnectForm.wireParams.WireNum = this.nWireNum;
			string attribute3 = xmlHelper.GetAttribute("CrossSection");
			if (!string.IsNullOrEmpty(attribute3))
			{
				this.dCrossSection = Convert.ToDouble(attribute3);
			}
			WireConnectForm.wireParams.CrossSection = this.dCrossSection;
			string attribute4 = xmlHelper.GetAttribute("LayMode");
			if (!string.IsNullOrEmpty(attribute4))
			{
				this.strLayMode = attribute4;
			}
			WireConnectForm.wireParams.LayMode = this.strLayMode;
			string attribute5 = xmlHelper.GetAttribute("Level");
			if (!string.IsNullOrEmpty(attribute5))
			{
				this.dLevel = Convert.ToDouble(attribute5);
			}
			WireConnectForm.wireParams.Level = this.dLevel;
			string attribute6 = xmlHelper.GetAttribute("ConduitTypeID");
			if (!string.IsNullOrEmpty(attribute6))
			{
				this.nConduitTypeID = Convert.ToInt32(attribute6);
			}
			foreach (RevitConduitType revitConduitType in ElectricSettingDataAssist.GetConduitTypesForWire(doc, WireConnectForm.wireParams.WireType))
			{
				if (revitConduitType.ConduitTypeId.ToString() == attribute6)
				{
					WireConnectForm.wireParams.ConduitTypeID = revitConduitType.ConduitTypeId;
					break;
				}
			}
			string attribute7 = xmlHelper.GetAttribute("ConduitDiameter");
			if (!string.IsNullOrEmpty(attribute7))
			{
				this.dConduitDiameter = Convert.ToDouble(attribute7);
			}
			WireConnectForm.wireParams.ConduitDiameter = this.dConduitDiameter;
			return true;
		}

		public string strWireType = "VV";

		public int nWireNum = 1;

		public int nConduitTypeID = 446703;

		public double dCrossSection = 4.0;

		public string strLayMode = "AB";

		public double dLevel;

		public double dConduitDiameter = 15.0;
	}
}
